package com.mentalhealthplatform.global.log.manager;

import com.mentalhealthplatform.global.rbac.model.User;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import com.mentalhealthplatform.global.log.enums.OperationStatus;
import com.mentalhealthplatform.global.log.enums.LogStatus;

import java.time.LocalDateTime;

@Getter
@Setter
@Entity
@Table(
        name = "manager_logs",
        indexes = {
                @Index(name = "idx_operator_id", columnList = "operator_id"),
                @Index(name = "idx_operation_time", columnList = "operation_time"),
                @Index(name = "idx_log_status", columnList = "logStatus"),
                @Index(name = "idx_system_module", columnList = "system_module"),
                @Index(name = "idx_operation_type", columnList = "operation_type"),
                @Index(name = "idx_system_module_status", columnList = "system_module, logStatus"),
                @Index(name = "idx_operator_operation_status", columnList = "operator_id, operation_status"),
                @Index(name = "idx_operation_time_elapsed_time", columnList = "operation_time, elapsed_time")
        }
)
public class ManagerLog {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "system_module", nullable = false)
    private String systemModule;

    @Column(name = "operation_type", nullable = false)
    private String operationType;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "operator_id", nullable = false, referencedColumnName = "id",
            foreignKey = @ForeignKey(name = "fk_operator_user"))
    private User operator;

    @Column(name = "operation_address")
    private String operationAddress;

    @Column(name = "operation_location")
    private String operationLocation;

    @Column(name = "http_method", nullable = false)
    private String httpMethod;

    @Enumerated(EnumType.STRING)
    @Column(name = "operation_status", nullable = false)
    private OperationStatus operationStatus;

    @CreationTimestamp
    @Column(name = "operation_time", nullable = false, updatable = false)
    private LocalDateTime operationTime;

    @Column(name = "elapsed_time")
    private Long elapsedTime;

    @Column(name = "request_url", nullable = false)
    private String requestUrl;

    @Column(name = "method_name", nullable = false)
    private String methodName;

    @Lob
    @Column(name = "request_params")
    private String requestParams;

    @Lob
    @Column(name = "response_params")
    private String responseParams;

    @Enumerated(EnumType.STRING)
    @Column(name = "log_status", nullable = false)
    private LogStatus logStatus;
}
